(* upper case text will be copied into this buffer *)
buf := TextModels.Clone(c.text); w := buf.NewWriter(NIL);
r := c.text.NewReader(NIL); r.SetPos(beg);
r.ReadChar(ch);
WHILE (r.Pos() <= end) & ~r.eot DO
IF (ch >= "a") & (ch <= "z") THEN ch := CAP(ch) END;
w.WriteChar(ch);
r.ReadChar(ch)
END;
Models.BeginScript(c.text, "Caps", script);
c.text.Delete(beg, end); c.text.CopyFrom(beg, buf, 0, end - beg);
Models.EndScript(c.text, script)
END
END Do;
END ObxCaps.
TextControllers.StdCtrlDesc
TextControllers.ControllerDesc
Containers.ControllerDesc
Controllers.ControllerDesc
TextRulers.StdRulerDesc
TextRulers.RulerDesc
TextRulers.StdStyleDesc
TextRulers.StyleDesc
TextRulers.AttributesDesc
Helvetica
DevCommanders.StdViewDesc
DevCommanders.ViewDesc
Helvetica
Oberon by Example: ObxCaps
This example shows how the built-in text subsystem of Oberon/F can be extended by new commands. To demonstrate this possibility, a command is shown which fetches the selection in the focus view (assuming the focus view is a text view), creates a new empty text, copies the selection into this new text (but with all small letters turned into capital letters), and then replaces the selection by the newly created text. In short, this command turns the selected text stretch into all capital letters.
As an example, select the test string several lines below, and then click on the following commander:
ObxCaps.Do
teSTstring834 .-st
You'll note that the selection has turned into all caps.
But now comes the surprise: execute Undo
Caps in the Edit menu. As a result, the effect of the uppercase operation is undone! In Oberon/F, most operations are undoable; this also holds for the Delete and CopyFrom procedures in the above example. Thus, you need to do nothing special in order to render such a command undoable!
However, you may have noticed that there is something special in the sample program: there is a BeginScript / EndScript pair of procedure calls before resp. after the calls to Delete / CopyFrom. They bundle the sequence of a Delete followed by a CopyFrom into one single compound
command, meaning that the user need not undo both of these operations individually, but rather in one single step.
In this example we have seen how an existing displayed text and its selection are accessed, how a buffer text is created, and how the selected text stretch is replaced by the buffer's contents.